package com.example.kumrulutest;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.AsyncTask;

public class WebServiceConnector extends AsyncTask<Void, Void, String> {
	
	// refer: http://stackoverflow.com/questions/5282739/object-to-array-of-string-in-android
	private static final String SOAP_ACTION = "http://ozancali.com/GetFormulas"; 
    private static final String METHOD_NAME = "GetFormulas";
    private static final String NAMESPACE = "http://ozancali.com/";
    private static final String URL = "http://ozancali.com/599/NetUcretService.asmx";

    private Exception exception;

    protected String doInBackground(Void... params) {
    	try {

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            //request.addProperty("pass", "pass");

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);

            Object result = (Object)envelope.getResponse();
            return result.toString();
            
        } catch (Exception e) {
        	this.exception = e;
            return e.getMessage();
            }
    }

    protected void onPostExecute() {
        // TODO: check this.exception 
    }
 }
